package com.feng.vhr.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.feng.vhr.pojo.Department;
import com.feng.vhr.pojo.Employee;
import com.feng.vhr.response.REmployee;
import org.apache.ibatis.annotations.*;

import java.util.Date;
import java.util.List;

/**
 * <p>
 * Mapper 接口
 * </p>
 *
 * @author feng
 * @since 2022-05-09
 */
public interface EmployeeMapper extends BaseMapper<Employee> {

    @Select({"<script>"+
            " select * from employee"+
            " <where>"+
            " <if test='emp.name!= null and emp.name !=\"\" '>"+
            " and name like concat('%',#{emp.name},'%') "+
            " </if>"+
            " <if test='emp.politicId!= null and emp.politicId !=\"\" '>"+
            " and politicId=#{emp.politicId}"+
            " </if>"+
            " <if test='emp.nationId!= null and emp.nationId !=\"\" '>"+
            " and nationId=#{emp.nationId}"+
            " </if>"+
            " <if test='emp.jobLevelId!= null and emp.jobLevelId !=\"\" '>"+
            " and jobLevelId=#{emp.jobLevelId}"+
            " </if>"+
            " <if test='emp.posId!= null and emp.posId !=\"\" '>"+
            " and posId=#{emp.posId}"+
            " </if>"+
            " <if test='emp.engageForm!= null and emp.engageForm !=\"\" '>"+
            " and engageForm=#{emp.engageForm}"+
            " </if>"+
            " <if test='emp.departmentId!= null and emp.departmentId !=\"\" '>"+
            " and departmentId=#{emp.departmentId}"+
            " </if>"+
            " <if test='beginDateScope!= null '>"+
            " and beginDate between #{beginDateScope[0]} and #{beginDateScope[1]}"+
            " </if>"+
            " </where>"+
            "</script>"
    })
    @Results({
            @Result(column = "id", property = "id"),
            @Result(column = "name", property = "name"),
            @Result(column = "gender", property = "gender"),
            @Result(column = "birthday", property = "birthday"),
            @Result(column = "idCard", property = "idCard"),
            @Result(column = "wedlock", property = "wedlock"),
            @Result(column = "nationId", property = "nationId"),
            @Result(column = "nativePlace", property = "nativePlace"),
            @Result(column = "politicId", property = "politicId"),
            @Result(column = "email", property = "email"),
            @Result(column = "phone", property = "phone"),
            @Result(column = "address", property = "address"),
            @Result(column = "departmentId", property = "departmentId"),
            @Result(column = "jobLevelId", property = "jobLevelId"),
            @Result(column = "posId", property = "posId"),
            @Result(column = "engageForm", property = "engageForm"),
            @Result(column = "tiptopDegree", property = "tiptopDegree"),
            @Result(column = "specialty", property = "specialty"),
            @Result(column = "school", property = "school"),
            @Result(column = "beginDate", property = "beginDate"),
            @Result(column = "workState", property = "workState"),
            @Result(column = "workID", property = "workID"),
            @Result(column = "contractTerm", property = "contractTerm"),
            @Result(column = "conversionTime", property = "conversionTime"),
            @Result(column = "notWorkDate", property = "notWorkDate"),
            @Result(column = "beginContract", property = "beginContract"),
            @Result(column = "endContract", property = "endContract"),
            @Result(column = "workAge", property = "workAge"),
            @Result(
                    column = "departmentId",
                    property = "department",
                    javaType = Department.class,
                    one = @One(select = "com.feng.vhr.mapper.DepartmentMapper.selectById")
            ),
            @Result(
                    column = "id",
                    property = "salary",
                    javaType = Department.class,
                    one = @One(select = "com.feng.vhr.mapper.SalaryMapper.getSalaryBySid")
            ),

            @Result(
                    column = "nationId",
                    property = "nation",
                    javaType = Department.class,
                    one = @One(select = "com.feng.vhr.mapper.NationMapper.selectById")
            ),
            @Result(
                    column = "politicId",
                    property = "politicsstatus",
                    javaType = Department.class,
                    one = @One(select = "com.feng.vhr.mapper.PoliticsstatusMapper.selectById")
            ),
            @Result(
                    column = "posId",
                    property = "position",
                    javaType = Department.class,
                    one = @One(select = "com.feng.vhr.mapper.PositionMapper.selectById")
            ),
            @Result(
                    column = "jobLevelId",
                    property = "jobLevel",
                    javaType = Department.class,
                    one = @One(select = "com.feng.vhr.mapper.JoblevelMapper.selectById")
            ),
    })
    public List<REmployee> getAllEmpInfo(@Param("emp") Employee emp,@Param("beginDateScope") Date[] beginDateScope);

    @Select("select max(workID) from employee ")
    public int maxWorkID();
}
